﻿$(document).ready(function() {
    //验证填写的信息
    //    $("#J_form input:visible").blur(function() {
    //        var t = $(this);
    //        var index = $.inArray(this, $.makeArray($("#J_form input:visible")));
    //        var reg = [/^[\S*]{1,20}$/, /^[\S*]{1,20}$/, /^[\S*]{1,20}$/, /^[\S*]{1,20}$/, /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/, /^(((13[0-9]{1})|(15[0-35-9]{1})|(18[05-9]{1}))+\d{8})$/];
    //        var val = t.val().replace(/(^\s*)|(\s*$)/g, "");
    //        var result = (!reg[index].exec(val)) ? "form-showerror" : "form-showsuccess";
    //        t.nextAll(".form-message").removeClass("form-showerror").removeClass("form-showsuccess").addClass(result);
    //        t.nextAll("span.texts").html(t.val());
    //    });
    var J_light = $("#J_light");
    var J_form = $("#J_form");
    J_form.find("button[type='submit']").click(function() {
        this.blur();
    });
    //初始化表单状态
    $("#J_form_check").val("0");
    //提交个人信息
    J_form.submit(function() {
        var t = $(this);
        //如果检查通过，直接提交
        if ($("#J_form_check").val() == "1") { return true; }
        //验证填写信息
        //        var t = $(this);
        //        var data = {};
        //        var field1 = t.find("input:hidden");
        //        var count1 = field1.length;
        //        for (var i = 0; i < count1; i++) {
        //            field = field1.eq(i);
        //            data[field.attr("name")] = field.val();
        //        };
        //        var field2 = t.find("input:visible");
        //        var count2 = field2.length;
        //        for (var i = 0; i < count2; i++) {
        //            field = field2.eq(i);
        //            field.focus();
        //            field.blur();
        //            data[field.attr("name")] = field.val();
        //        };
        //        if (t.find(".form-showerror").length > 0) {
        //            return false;
        //        };
        //高亮检查
        var light = $("#J_light");
        light.show();
        light.find(".light-bg").css("height", $(document).height());
        light.find(".light-box").css({ left: ($("#J_form").offset().left + 200), top: $("#J_form").offset().top + 50 });
        light.find(".light-iframe").css("height", $(document).height());
        var html = "<table><tr>";
        var label = t.find("[data-tolight='label']");
        var content = t.find("[data-tolight='content']");
        var count = label.length;
        for (var i = 0; i < count; i++) {
            var a = "<td class='label'>" + label.eq(i).html().replace(/<[^>]*>/ig, "").replace("*", "") + "</td>";
            a += (i == 0) ? "<td colspan='3'>" : "<td>";
            var c = content.eq(i);
            if (c.find("input[type='radio']").length > 0) {
                a += "<span class='orange'>" + c.find("input[type='radio']:checked").attr("title") + "</span>";
            } else if (c.find("input[type='text']").length > 0) {
                var ct = c.find("input[type='text']");
                var num = ct.length;
                for (var j = 0; j < num; j++) {
                    a += "<span class='orange'>" + ct.eq(j).val() + "</span>";
                }
            } else if (c.find("select").length > 0) {
                var ct = c.find("select");
                var num = ct.length;
                var select = "";
                for (var j = 0; j < num; j++) {
                    select += ct.eq(j).find("option:selected").text() + "/";
                };
                select = "<span class='orange'>" + select.substring(0, select.length - 1) + "</span>";
                a += select;
            } else {
                a += c.html();
            }
            a += (i % 2 == 0) ? "</td></tr><tr>" : "</td>";
            html += a;
        };
        html += "</table>";
        light.find(".light-form").html(html);
        return false;
    });

    J_light.find("button[type='submit']").click(function() {
        $("#J_form_check").val("1");
        J_form.submit();
    });
    J_light.find("button[type='reset']").click(function() {
        J_light.hide();
    });
    J_light.find(".light-close").click(function() {
        J_light.hide();
    });
});